// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ingest
{
	public sealed class IngestPutPipelineRequestParameters : RequestParameters<IngestPutPipelineRequestParameters>
	{
		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Duration? MasterTimeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("master_timeout"); set => Q("master_timeout", value); }

		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Duration? Timeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("timeout"); set => Q("timeout", value); }

		[JsonIgnore]
		public long? IfVersion { get => Q<long?>("if_version"); set => Q("if_version", value); }
	}

	public sealed partial class IngestPutPipelineRequest : PlainRequestBase<IngestPutPipelineRequestParameters>
	{
		public IngestPutPipelineRequest(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id))
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.IngestPutPipeline;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Duration? MasterTimeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("master_timeout"); set => Q("master_timeout", value); }

		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Duration? Timeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("timeout"); set => Q("timeout", value); }

		[JsonIgnore]
		public long? IfVersion { get => Q<long?>("if_version"); set => Q("if_version", value); }

		[JsonInclude]
		[JsonPropertyName("_meta")]
		public Dictionary<string, object>? Meta { get; set; }

		[JsonInclude]
		[JsonPropertyName("description")]
		public string? Description { get; set; }

		[JsonInclude]
		[JsonPropertyName("on_failure")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? OnFailure { get; set; }

		[JsonInclude]
		[JsonPropertyName("processors")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? Processors { get; set; }

		[JsonInclude]
		[JsonPropertyName("version")]
		public long? Version { get; set; }
	}

	public sealed partial class IngestPutPipelineRequestDescriptor<TDocument> : RequestDescriptorBase<IngestPutPipelineRequestDescriptor<TDocument>, IngestPutPipelineRequestParameters>
	{
		internal IngestPutPipelineRequestDescriptor(Action<IngestPutPipelineRequestDescriptor<TDocument>> configure) => configure.Invoke(this);
		public IngestPutPipelineRequestDescriptor(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id))
		{
		}

		internal IngestPutPipelineRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.IngestPutPipeline;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		public IngestPutPipelineRequestDescriptor<TDocument> IfVersion(long? ifVersion) => Qs("if_version", ifVersion);
		public IngestPutPipelineRequestDescriptor<TDocument> MasterTimeout(Elastic.Clients.Elasticsearch.Duration? masterTimeout) => Qs("master_timeout", masterTimeout);
		public IngestPutPipelineRequestDescriptor<TDocument> Timeout(Elastic.Clients.Elasticsearch.Duration? timeout) => Qs("timeout", timeout);
		public IngestPutPipelineRequestDescriptor<TDocument> Id(Elastic.Clients.Elasticsearch.Id id)
		{
			RouteValues.Required("id", id);
			return Self;
		}

		private IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? OnFailureValue { get; set; }

		private ProcessorContainerDescriptor<TDocument> OnFailureDescriptor { get; set; }

		private Action<ProcessorContainerDescriptor<TDocument>> OnFailureDescriptorAction { get; set; }

		private Action<ProcessorContainerDescriptor<TDocument>>[] OnFailureDescriptorActions { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? ProcessorsValue { get; set; }

		private ProcessorContainerDescriptor<TDocument> ProcessorsDescriptor { get; set; }

		private Action<ProcessorContainerDescriptor<TDocument>> ProcessorsDescriptorAction { get; set; }

		private Action<ProcessorContainerDescriptor<TDocument>>[] ProcessorsDescriptorActions { get; set; }

		private Dictionary<string, object>? MetaValue { get; set; }

		private string? DescriptionValue { get; set; }

		private long? VersionValue { get; set; }

		public IngestPutPipelineRequestDescriptor<TDocument> OnFailure(IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? onFailure)
		{
			OnFailureDescriptor = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = null;
			OnFailureValue = onFailure;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor<TDocument> OnFailure(ProcessorContainerDescriptor<TDocument> descriptor)
		{
			OnFailureValue = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = null;
			OnFailureDescriptor = descriptor;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor<TDocument> OnFailure(Action<ProcessorContainerDescriptor<TDocument>> configure)
		{
			OnFailureValue = null;
			OnFailureDescriptor = null;
			OnFailureDescriptorActions = null;
			OnFailureDescriptorAction = configure;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor<TDocument> OnFailure(params Action<ProcessorContainerDescriptor<TDocument>>[] configure)
		{
			OnFailureValue = null;
			OnFailureDescriptor = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = configure;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor<TDocument> Processors(IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? processors)
		{
			ProcessorsDescriptor = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = null;
			ProcessorsValue = processors;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor<TDocument> Processors(ProcessorContainerDescriptor<TDocument> descriptor)
		{
			ProcessorsValue = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = null;
			ProcessorsDescriptor = descriptor;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor<TDocument> Processors(Action<ProcessorContainerDescriptor<TDocument>> configure)
		{
			ProcessorsValue = null;
			ProcessorsDescriptor = null;
			ProcessorsDescriptorActions = null;
			ProcessorsDescriptorAction = configure;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor<TDocument> Processors(params Action<ProcessorContainerDescriptor<TDocument>>[] configure)
		{
			ProcessorsValue = null;
			ProcessorsDescriptor = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = configure;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor<TDocument> Meta(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
		{
			MetaValue = selector?.Invoke(new FluentDictionary<string, object>());
			return Self;
		}

		public IngestPutPipelineRequestDescriptor<TDocument> Description(string? description)
		{
			DescriptionValue = description;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor<TDocument> Version(long? version)
		{
			VersionValue = version;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (OnFailureDescriptor is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, OnFailureDescriptor, options);
				writer.WriteEndArray();
			}
			else if (OnFailureDescriptorAction is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor<TDocument>(OnFailureDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (OnFailureDescriptorActions is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				foreach (var action in OnFailureDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor<TDocument>(action), options);
				}

				writer.WriteEndArray();
			}
			else if (OnFailureValue is not null)
			{
				writer.WritePropertyName("on_failure");
				JsonSerializer.Serialize(writer, OnFailureValue, options);
			}

			if (ProcessorsDescriptor is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, ProcessorsDescriptor, options);
				writer.WriteEndArray();
			}
			else if (ProcessorsDescriptorAction is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor<TDocument>(ProcessorsDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (ProcessorsDescriptorActions is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				foreach (var action in ProcessorsDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor<TDocument>(action), options);
				}

				writer.WriteEndArray();
			}
			else if (ProcessorsValue is not null)
			{
				writer.WritePropertyName("processors");
				JsonSerializer.Serialize(writer, ProcessorsValue, options);
			}

			if (MetaValue is not null)
			{
				writer.WritePropertyName("_meta");
				JsonSerializer.Serialize(writer, MetaValue, options);
			}

			if (!string.IsNullOrEmpty(DescriptionValue))
			{
				writer.WritePropertyName("description");
				writer.WriteStringValue(DescriptionValue);
			}

			if (VersionValue is not null)
			{
				writer.WritePropertyName("version");
				JsonSerializer.Serialize(writer, VersionValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class IngestPutPipelineRequestDescriptor : RequestDescriptorBase<IngestPutPipelineRequestDescriptor, IngestPutPipelineRequestParameters>
	{
		internal IngestPutPipelineRequestDescriptor(Action<IngestPutPipelineRequestDescriptor> configure) => configure.Invoke(this);
		public IngestPutPipelineRequestDescriptor(Elastic.Clients.Elasticsearch.Id id) : base(r => r.Required("id", id))
		{
		}

		internal IngestPutPipelineRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.IngestPutPipeline;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		public IngestPutPipelineRequestDescriptor IfVersion(long? ifVersion) => Qs("if_version", ifVersion);
		public IngestPutPipelineRequestDescriptor MasterTimeout(Elastic.Clients.Elasticsearch.Duration? masterTimeout) => Qs("master_timeout", masterTimeout);
		public IngestPutPipelineRequestDescriptor Timeout(Elastic.Clients.Elasticsearch.Duration? timeout) => Qs("timeout", timeout);
		public IngestPutPipelineRequestDescriptor Id(Elastic.Clients.Elasticsearch.Id id)
		{
			RouteValues.Required("id", id);
			return Self;
		}

		private IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? OnFailureValue { get; set; }

		private ProcessorContainerDescriptor OnFailureDescriptor { get; set; }

		private Action<ProcessorContainerDescriptor> OnFailureDescriptorAction { get; set; }

		private Action<ProcessorContainerDescriptor>[] OnFailureDescriptorActions { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? ProcessorsValue { get; set; }

		private ProcessorContainerDescriptor ProcessorsDescriptor { get; set; }

		private Action<ProcessorContainerDescriptor> ProcessorsDescriptorAction { get; set; }

		private Action<ProcessorContainerDescriptor>[] ProcessorsDescriptorActions { get; set; }

		private Dictionary<string, object>? MetaValue { get; set; }

		private string? DescriptionValue { get; set; }

		private long? VersionValue { get; set; }

		public IngestPutPipelineRequestDescriptor OnFailure(IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? onFailure)
		{
			OnFailureDescriptor = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = null;
			OnFailureValue = onFailure;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor OnFailure(ProcessorContainerDescriptor descriptor)
		{
			OnFailureValue = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = null;
			OnFailureDescriptor = descriptor;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor OnFailure(Action<ProcessorContainerDescriptor> configure)
		{
			OnFailureValue = null;
			OnFailureDescriptor = null;
			OnFailureDescriptorActions = null;
			OnFailureDescriptorAction = configure;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor OnFailure(params Action<ProcessorContainerDescriptor>[] configure)
		{
			OnFailureValue = null;
			OnFailureDescriptor = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = configure;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor Processors(IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? processors)
		{
			ProcessorsDescriptor = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = null;
			ProcessorsValue = processors;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor Processors(ProcessorContainerDescriptor descriptor)
		{
			ProcessorsValue = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = null;
			ProcessorsDescriptor = descriptor;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor Processors(Action<ProcessorContainerDescriptor> configure)
		{
			ProcessorsValue = null;
			ProcessorsDescriptor = null;
			ProcessorsDescriptorActions = null;
			ProcessorsDescriptorAction = configure;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor Processors(params Action<ProcessorContainerDescriptor>[] configure)
		{
			ProcessorsValue = null;
			ProcessorsDescriptor = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = configure;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor Meta(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
		{
			MetaValue = selector?.Invoke(new FluentDictionary<string, object>());
			return Self;
		}

		public IngestPutPipelineRequestDescriptor Description(string? description)
		{
			DescriptionValue = description;
			return Self;
		}

		public IngestPutPipelineRequestDescriptor Version(long? version)
		{
			VersionValue = version;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (OnFailureDescriptor is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, OnFailureDescriptor, options);
				writer.WriteEndArray();
			}
			else if (OnFailureDescriptorAction is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor(OnFailureDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (OnFailureDescriptorActions is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				foreach (var action in OnFailureDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor(action), options);
				}

				writer.WriteEndArray();
			}
			else if (OnFailureValue is not null)
			{
				writer.WritePropertyName("on_failure");
				JsonSerializer.Serialize(writer, OnFailureValue, options);
			}

			if (ProcessorsDescriptor is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, ProcessorsDescriptor, options);
				writer.WriteEndArray();
			}
			else if (ProcessorsDescriptorAction is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor(ProcessorsDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (ProcessorsDescriptorActions is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				foreach (var action in ProcessorsDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor(action), options);
				}

				writer.WriteEndArray();
			}
			else if (ProcessorsValue is not null)
			{
				writer.WritePropertyName("processors");
				JsonSerializer.Serialize(writer, ProcessorsValue, options);
			}

			if (MetaValue is not null)
			{
				writer.WritePropertyName("_meta");
				JsonSerializer.Serialize(writer, MetaValue, options);
			}

			if (!string.IsNullOrEmpty(DescriptionValue))
			{
				writer.WritePropertyName("description");
				writer.WriteStringValue(DescriptionValue);
			}

			if (VersionValue is not null)
			{
				writer.WritePropertyName("version");
				JsonSerializer.Serialize(writer, VersionValue, options);
			}

			writer.WriteEndObject();
		}
	}
}